package com.oos.zone.wechat.cp.service.handler;

import lombok.extern.log4j.Log4j2;
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * 功能描述：普通消息处理器
 *
 * @author 拓金辉
 * @version 1.0
 * @date 2021-08-09 09:16:24
 */
@Log4j2
@Service
public class WxCpStandardMessageHandler extends AbstractWxCpMessageHandler {

    @Override
    public WxCpXmlOutMessage doHandle() {
        switch (wxMessage.getMsgType()) {
            case "text":
                return text();
            case "image":
                return image();
            case "voice":
                return voice();
            case "video":
                return video();
            case "shortvideo":
                return shortvideo();
            case "location":
                return location();
            case "link":
                return link();
            case "file":
                return file();
            default:
                log.error("\n\n【事件类型未处理】\n\n {}", wxMessage.toString());
                return defaultTextMessage;
        }
    }

    public WxCpXmlOutMessage text() {
        CompletableFuture.runAsync(() -> log.info("文本消息\n"), executor);
        return WxCpXmlOutMessage.TEXT().fromUser(String.valueOf(wxMessage.getAgentId())).toUser(wxMessage.getFromUserName()).content(wxMessage.getContent()).build();
    }

    public WxCpXmlOutMessage image() {
        CompletableFuture.runAsync(() -> log.info("图片消息\n"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage voice() {
        CompletableFuture.runAsync(() -> log.info("语音消息\n"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage video() {
        CompletableFuture.runAsync(() -> log.info("视频消息\n"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage shortvideo() {
        CompletableFuture.runAsync(() -> log.info("小视频消息\n"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage location() {
        CompletableFuture.runAsync(() -> log.info("地理位置消息\n"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage link() {
        CompletableFuture.runAsync(() -> log.info("链接消息\n"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage file() {
        CompletableFuture.runAsync(() -> log.info("文件消息\n"), executor);
        return defaultTextMessage;
    }

}
